/**
* ImageManager.h
* Holds a Dynamic Array ("MooseArray") of some item.  Class will handle
* loading the assets on program load, as well as doing searches for the desired graphic and
* returning the appropriate integer ID.
*
* @date 2010-12-03
* @author Rachel J. Morris
*
* http://www.moosader.com/
* http://code.google.com/p/unicorn-princess/
* GNU GPL v3 license
*/

#ifndef _ManagerTemplate
#define _ManagerTemplate

#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#include <string>
#include <iostream>

#include "MooseArray.hpp"

template <class ITEM>

class ManagerTemplate
{
    protected:
        MooseArray<ITEM> _asset;

        int FindAsset( std::string findName )
        {
            for ( int i=0; i<_asset.Size(); i++ )
            {
                if ( _asset[i].name == findName )
                {
                    return i;
                }
            }

            return 0;
        }
    public:
        ManagerTemplate() { ; }
        ~ManagerTemplate() { ; }

        void LoadAssets( std::string& assetPath, MooseArray<std::string>& assetList )
        {
            for ( int i=0; i<assetList.Size(); i++ )
            {
                ITEM newasset;
                newasset.Load( assetPath + assetList[i] );
                _asset.Push( newasset );
            }
        }

        /**
        * Return asset based on it's string identifier
        * @param    std::string     name        Name of teh image we're looking for.  Will be filename minus the path and suffix.
        * @return   ITEM                        Returns the templated item type
        */
        ITEM& GetAsset( std::string name )
        {
            int index = FindAsset( name );

            return GetAsset( index );
        }

        /**
        * Returns asset based on it's index
        * @param    int     index           Index of the image
        * @return   ITEM                    Returns the templated item type
        */
        ITEM& GetAsset( int index )
        {
            if ( index < _asset.Size() && index >= 0 );
                return _asset[index];
        }
};

#endif
